var Game = require('Game');
cc.Class({
    extends: cc.Component,

    properties: {
        btnChips: {
            default: [],
            type: cc.Node
        },
        chipValues: {
            default: [],
            type: cc.Integer
        },
         chipsBg : {
            default: [],
            type: cc.spriteFrame
        },
        indexSelect:cc.Integer 
    },
    onLoad(){
        cc.resources.load("atlas/game", cc.SpriteAtlas, (err, atlas) => {
             this.chipsBg[0] = atlas.getSpriteFrame('btn_select');
             this.chipsBg[1] = atlas.getSpriteFrame('btn_default');    
         })
    },

    init: function () {
        cc.log('========Btn init()');
        this._registerBtns();
    },

    _registerBtns: function () {
        var self = this;
        var registerBtn = function (index) {
            self.btnChips[i].on('touchstart', function (event) {
                self .playAddChip(self.chipValues[index]);
               
            }, this);
        };
        for (var i = 0; i < self.btnChips.length; ++i) {
            registerBtn(i);
            cc.log('========押注按钮'+i);
        }
    },


    playAddChip: function (delta) {
        cc.log('========押注按钮'); 
        Game.instance.audioMng.playChips();
        let selectFlag=Game.instance.gameKernel.selectFlag;
        Game.instance.gameKernel.addStake(selectFlag,delta);
      
    },
 
    btnF5Score(){
       // Game.instance.mToast.show('刷新金币',3);
        Game.instance.gameKernel.getScore();
    },
    btnAddScore(){
        let str=  Game.instance.LL.t('label.tips4'); 
        Game.instance.mToast.show(str,3);
    },
    btnGameList(){
      let str=  Game.instance.LL.t('label.tips4'); 
        Game.instance.mToast.show(str,3);
       // Game.instance.ws.liveRoom();
    },
    btnGameDesc(){
       // Game.instance.mToast.show('游戏说明',3);
        Game.instance.popDescShow(true);
    },
    btnGameDescDismiss(){
    
        Game.instance.popDescShow(false);
    },
 
    selectBig:function(){
        var score= this.chipValues[this.indexSelect];
        Game.instance.gameKernel.selectBig(score);

    },
    selectSmall:function(){
        var score= this.chipValues[this.indexSelect];
        Game.instance.gameKernel.selectSmall(score);
       
    },
    btnGameSetting(){
       // Game.instance.mToast.show('游戏设置',3);
        Game.instance.popSettingShow(true);

    },

    btnGameSettingDismiss(){
        Game.instance.popSettingShow(false);

    },
    popTipsDismiss(){
        Game.instance.mPopTips.hide();

    },

    exitGame() {
        // 关闭当前窗口
        window.close();
    }
    
});
